package cn.keniykey.mc.viewlibrary.container.api;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Nullable;

public enum EClickType {
	ALL(-1, -1),
	LEFT(0, 0),
	RIGHT(0, 1),
	SHIFT_LEFT(1, 0),
	SHIFT_RIGHT(1, 1),
	OFFHAND(2, 40),
	NUMBER_KEY(2, -1),
	NUMBER_KEY_1(2, 0),
	NUMBER_KEY_2(2, 1),
	NUMBER_KEY_3(2, 2),
	NUMBER_KEY_4(2, 3),
	NUMBER_KEY_5(2, 4),
	NUMBER_KEY_6(2, 5),
	NUMBER_KEY_7(2, 6),
	NUMBER_KEY_8(2, 7),
	NUMBER_KEY_9(2, 8),
	MIDDLE(3, 2),
	DROP(4, 0),
	CONTROL_DROP(4, 1),
    ABROAD_LEFT_EMPTY(4, 0),
    ABROAD_RIGHT_EMPTY(4, 1),
    ABROAD_LEFT_ITEM(0, 0),
    ABROAD_RIGHT_ITEM(0, 1),
    LEFT_MOUSE_DRAG_ADD(5, 1),
    RIGHT_MOUSE_DRAG_ADD(5, 5),
    MIDDLE_MOUSE_DRAG_ADD(5, 9),
    DOUBLE_CLICK(6, 0),
    UNKNOWN(-1, -1);
	
	private final int mode,button;
	
	private EClickType(int mode1, int button1) {
		this.mode = mode1;
		this.button = button1;
	}
	
	public boolean isLeftClick() {
		return (this == LEFT || this == SHIFT_LEFT);
	}
	public boolean isRightClick() {
		return (this == RIGHT || this == SHIFT_RIGHT);
	}
	public boolean isShiftClick() {
		return (this == SHIFT_LEFT || this == SHIFT_RIGHT);
	}
	public boolean isNumberKeyClick() {
		switch(this) {
		case NUMBER_KEY:
		case NUMBER_KEY_1:
		case NUMBER_KEY_2:
		case NUMBER_KEY_3:
		case NUMBER_KEY_4:
		case NUMBER_KEY_5:
		case NUMBER_KEY_6:
		case NUMBER_KEY_7:
		case NUMBER_KEY_8:
		case NUMBER_KEY_9:
		case OFFHAND:
			return true;
		default:
		}
		return false;
	}
	public boolean isKeyboardClick() {
		return (this.isNumberKeyClick() || this == DROP || this == CONTROL_DROP);
	}
	public boolean isDoubleClick() {
		return this == DOUBLE_CLICK;
	}
	public boolean isCreativeAction() {
		return (this == MIDDLE || this == MIDDLE_MOUSE_DRAG_ADD);
	}
	public boolean isItemMoveable() {
		return (isKeyboardClick() || isShiftClick() || isCreativeAction() || isDoubleClick());
	}
	public boolean equals(int mode1, int button1) {
		return (this.mode == mode1 && this.button == button1);
	}
	
	private static final List<String> strmodes = Arrays.asList("PICKUP","QUICK_MOVE","SWAP","CLONE","THROW","QUICK_CRAFT","PICKUP_ALL");
	
	@Nullable
	public static EClickType getMatch(int mode1, int button1, int slot1) {
		if(slot1 == -999) {
			if(LEFT.equals(mode1, button1)) return ABROAD_LEFT_ITEM;
			if(RIGHT.equals(mode1, button1)) return ABROAD_RIGHT_ITEM;
			if(ABROAD_LEFT_EMPTY.equals(mode1, button1)) return ABROAD_LEFT_EMPTY;
			if(ABROAD_RIGHT_EMPTY.equals(mode1, button1)) return ABROAD_RIGHT_EMPTY;
			return UNKNOWN;
		}
		for(final EClickType type : values()) {
			if(type.equals(mode1, button1)) return type;
		}
		return null;
	}
	@Nullable
	public static EClickType getMatch(String mode1, int button1, int slot1) {
		return getMatch(strmodes.indexOf(mode1), button1, slot1);
	}
}